package com.xrx.webtemplate.shiro.permission;

import org.apache.shiro.authz.Permission;
import org.apache.shiro.util.AntPathMatcher;
import org.apache.shiro.util.PatternMatcher;

/**
 * Created by xierongxian on 2017/4/23.
 */
public class UrlPermission implements Permission {

    private String url;

    public UrlPermission(){}
    public UrlPermission(String p){
        this.url=p;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * 处理Permission 改为URL Permission
     * */
    public boolean implies(Permission p) {
        //判断是否是当前的urlPermission
        if(!(p instanceof UrlPermission))return false;
        UrlPermission up=(UrlPermission)p;
        //进行Permission的对比
        PatternMatcher patternMatcher=new AntPathMatcher();
        return patternMatcher.matches(this.getUrl(),up.getUrl());
    }
}
